# encoding: utf-8
class SettingsController < ApplicationController
  def index
    render
  end

  def changepassword
    flash[:error], flash[:notice] =nil
    flash[:error] = "不可为空." if params[:cp]=="" || params[:np]=="" ||params[:nnp]==""
    m =Mconfig.find_by_cname("password")
    flash[:error] = "原密码输入错误." if m.cvalue != Digest::MD5.hexdigest(params[:cp]) && flash[:error].nil?
    flash[:error] = "新密码两次输入不一致." if params[:np]!=params[:nnp] && flash[:error].nil?
    if flash[:error].nil?
      m.cvalue =Digest::MD5.hexdigest(params[:np])
      if m.save
        flash[:notice] ="修改成功!请重新登陆."
        redirect_to "/login"
        return
      else
        flash[:error] ="修改失败."
      end
    end
    render :action=>:index
  end
end
